package cz.uvn.orthopedy.client.ui.editor;

import com.google.gwt.user.client.ui.Composite;

import cz.uvn.orthopedy.client.ApplicationController;
import cz.uvn.orthopedy.client.entity.Doctor;
import cz.uvn.orthopedy.client.entity.Operation;
import cz.uvn.orthopedy.client.entity.ScheduleEntry;
import com.google.gwt.user.client.ui.DockPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.HasVerticalAlignment;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Button;

public class ScheduleEntryEditor extends Composite {
	private ApplicationController controller;
	private ScheduleEntry entry;
	
	private Label lblOwner;
	private Label lblDescription;
	private HorizontalPanel horizontalPanel;
	private Button btnEdit;
	private Button btnIndikacniList;

	public ScheduleEntryEditor(ApplicationController controller, ScheduleEntry entry) {
		this.controller = controller;
		this.entry = entry;
		
		initUI();
		ScheduleEntry.Type type = entry.getType();
		Doctor doctor = controller.getDoctorByID(entry.getOwnerId());
		String owner = doctor != null ? doctor.getSurname() : "<unknown doctor>";
		if (type == ScheduleEntry.Type.Owned) {
			lblOwner.setText(owner);
			Operation.Type opType = entry.getOperationType();
			lblDescription.setText(opType != null ? opType.toString() : "<unknown type>");
		} else if (type == ScheduleEntry.Type.Reserve) {
			lblOwner.setText(owner);
			lblDescription.setText("Rezerva");
		} else if (type == ScheduleEntry.Type.General) {
			Operation.Type opType = entry.getOperationType();
			lblDescription.setText(opType != null ? opType.toString() : "<unknown type>");
		}
	}

	private void initUI() {
		DockPanel dockPanel = new DockPanel();
		dockPanel.setStyleName("journalEntry");
		initWidget(dockPanel);
		
		lblOwner = new Label();
		lblOwner.setStyleName("boldLabel");
		dockPanel.add(lblOwner, DockPanel.NORTH);
		dockPanel.setCellVerticalAlignment(lblOwner, HasVerticalAlignment.ALIGN_MIDDLE);
		dockPanel.setCellHorizontalAlignment(lblOwner, HasHorizontalAlignment.ALIGN_CENTER);
		
		lblDescription = new Label();
		dockPanel.add(lblDescription, DockPanel.CENTER);
		dockPanel.setCellHorizontalAlignment(lblDescription, HasHorizontalAlignment.ALIGN_CENTER);
		
		horizontalPanel = new HorizontalPanel();
		horizontalPanel.setSpacing(3);
		horizontalPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
		dockPanel.add(horizontalPanel, DockPanel.SOUTH);
		dockPanel.setCellHorizontalAlignment(horizontalPanel, HasHorizontalAlignment.ALIGN_RIGHT);
		
		btnEdit = new Button("Edit");
		horizontalPanel.add(btnEdit);
		horizontalPanel.setCellHorizontalAlignment(btnEdit, HasHorizontalAlignment.ALIGN_RIGHT);
		
		btnIndikacniList = new Button("Indikacni List");
		horizontalPanel.add(btnIndikacniList);
		horizontalPanel.setCellHorizontalAlignment(btnIndikacniList, HasHorizontalAlignment.ALIGN_RIGHT);
	}

}
